package com.example.yeujian5.yuejian5.adapter;

import android.content.Context;
import android.net.Uri;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.MediaController;
import android.widget.VideoView;

import com.example.yeujian5.yuejian5.R;
import com.example.yeujian5.yuejian5.bean.MasterVideoBean;
import com.example.yeujian5.yuejian5.config.Config;

import java.util.List;

/**
 * Created by wangmengmeng on 2017/10/19.
 */




public class MasterVideoAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>{


    private Context mContext;//承载上下文
    private List<MasterVideoBean.MvideoEntity> mDataList;//动态数组承载数据使用
    private LayoutInflater mLayoutInflater;

    public MasterVideoAdapter(Context mContext,List<MasterVideoBean.MvideoEntity> mDataList){
        this.mContext=mContext;
        this.mDataList=mDataList;
        mLayoutInflater=LayoutInflater.from(mContext);
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View v=mLayoutInflater.from(parent.getContext()).inflate(R.layout.cardview_video,parent,false);
        return new MasterVideoAdapter.ViewHolder(v);
    }



    //将数据绑定到控件
    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        final  MasterVideoBean.MvideoEntity entity=mDataList.get(position);
        if (null==entity)
            return;
        MasterVideoAdapter.ViewHolder viewHolder = (MasterVideoAdapter.ViewHolder) holder;
        String internetUrl = Config.VIDEO_URL+entity.getUrl();
        if(!entity.getUrl().isEmpty())
        {
            viewHolder.video.setVideoURI(Uri.parse(internetUrl));
            MediaController controller =new MediaController(mContext);
            viewHolder.video.setMediaController(controller);
            controller.setMediaPlayer(viewHolder.video);

        }
        else
        {}





    }




    @Override
    public int getItemCount() {
        return mDataList.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder{
        VideoView video;

        public ViewHolder(View itemView) {
            super(itemView);
            video=(VideoView) itemView.findViewById(R.id.video);
        }
    }

}
